const app = getApp()

Page({

  //页面的初始数据
  data: {
    onvar:false,
    varcode:'',
    item:[]
  },
  //监听页面显示
  onLoad: function (options) {
    this.setData({
      id:options.id,
    })
    this.data.isvar = app.util().isNull(options.var) ? false : true
    this.getApi();
  },
  //读取我的订单
  getApi: function() {
    app.api().Get('api/v1/ais/shoporder/views',{id: this.data.id},(result) => {
      this.setData({
        item: result.data
      });
      if(this.data.isvar){
        this.onVer();
      }
    })
  },
  //订单重新支付
  doPayment(){
    wx.showLoading({
      title:'加载中'
    })
    app.api().Post('api/v1/ais/shoppay/payment',{id:this.data.item.shop_id},(res) => {
      if (res.code == 200) {
        wx.hideLoading()
        app.doWechatPay(res.data,()=>{
          var item = this.data.item;
              item['paid_at'] = 1; 
          this.setData({
            item: item
          });
        },()=>{
          app.wxAlert('你取消了支付')
        })
      }
    })
  },
  //订单核心
  onVer() {
    this.setData({
      onvar:!this.data.onvar
    })
    if(this.data.onvar){
      app.api().Post('openapi/v1/user/MiniProgramQrCode',{
        scene: {
          id:this.data.item.id
        },
        page: 'pages/shop/user/verification',
        name: this.data.item.order_no
      },(result) =>{
        this.setData({
          varcode: result.data,
        })
      })
    }
  },
  //状态更改
  finished(event) {
    var item = this.data.item;
        item['is_del'] = 1; 
    this.setData({
      item:item
    })
  }
})